package com.itheima.HomeWork.homework01;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class Books {
    public static void main(String[] args) throws DocumentException {
        SAXReader sax = new SAXReader();
        Document read = sax.read(new File("E:\\heima\\daima\\DarHorse\\moudule03\\properties-xml-logback-app\\src\\com\\itheima\\HomeWork\\homework01\\books.xml"));//读取xml文件
        Element rootElement = read.getRootElement();//获取根元素
        List<Element> elements = rootElement.elements();//获取根元素的子元素
        for (Element element : elements) {
            Attribute attribute = element.attribute("id");//获取id
            String id = attribute.getText();

            Element name = element.element("name");
            String nametext = name.getText();

            Element publishing = element.element("publishing");
            String publishingtext = publishing.getText();

            Element date = element.element("date");
            String datetext = date.getText();

            Element price = element.element("price");
            String pricetext = price.getText();
            System.out.println("书名：" + nametext + "，出版社：" + publishingtext + "，出版日期：" + datetext + "，价格：" + pricetext);
        }
    }
}
